// subHoliday/holidayCount/holidayCount.js
const appg = getApp().globalData
Page({
  /**
   * 页面的初始数据
   */
  data: {
    uid: null,
    userType: null,
    position_ID: null,
    count: {
      holiday_count: 0,
      sign_count: 0
    },
    TodayLeaveList: [],
    TodaySignList: []
  },
  async getData() {
    wx.showLoading({
      title: '加载中',
    })
    const params = {
      uid: this.data.uid,
      userType: this.data.userType,
      type: this.data.value1,
      day: 'a',
      position_ID: this.data.position_ID
    }
    const json = await getApp().$axios("/getDataKanBan", "POST", params)
    wx.hideLoading()
    if (json.status !== 200) {
      wx.showToast({
        title: '查询有误，请重试',
        icon: 'none'
      })
      return
    }
    this.setData({
      'count.holiday_count': json.data.holidayCount,
      'count.sign_count': json.data.signInCount
    })
  },
  // 获取请假人信息
  async getHolidayInfo() {
    let code = "/getTodayLeaveList?t=" + this.data.uid+"&school_ID="+appg.userInfo.school_ID
    try {
      const json = await getApp().$axios(code, 'GET');
      if (json.status !== 200) {
        wx.showToast({
          title: '获取统计数据异常',
          icon: 'none'
        })
        return
      }
      this.setData({
        TodayLeaveList: json.data
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  // 获取签到的信息统计
  async getSignInfo() {
    let code = "/getTeacherDataSign?id=" + this.data.uid
    try {
      const json = await getApp().$axios(code, 'GET');
      if (json.status !== 200) {
        wx.showToast({
          title: '获取统计数据异常',
          icon: 'none'
        })
        return
      }
      this.setData({
        TodaySignList: json.data
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      uid: appg.userInfo.id,
      userType: appg.userInfo.identity_ID,
      position_ID: appg.userInfo.position_ID
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getSignInfo()
    this.getData()
    this.getHolidayInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})